package com.grm.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.grm.entity.User;
import com.grm.mapper.UserMapper;

@RestController
public class UserController {
	@Autowired
	private UserMapper userMapper;

	@PostMapping("/user/save")
	public String save() {
		for (int i = 0; i < 10; i++) {
			User user = new User();
			user.setId((long) i);
			user.setName("test" + i);
			user.setCityId(1 % 2 == 0 ? 1 : 2);
			user.setCreateTime(new Date());
			user.setSex(i % 2 == 0 ? 1 : 2);
			user.setPhone("11111111" + i);
			user.setEmail("xxxxx");
			user.setCreateTime(new Date());
			user.setPassword("eeeeeeeeeeee");
			userMapper.save(user);
		}
		return "success";
	}

	@GetMapping("/user/get/{id}")
	public User get(@PathVariable Long id) {
		User user = userMapper.get(id);
		System.out.println(user.getId());
		return user;
	}
}
